#include <iostream>

using namespace std;
struct TreeNode {
      int val;
      TreeNode *left;
      TreeNode *right;
      TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 };


 class Solution {
    private:

        bool flag;

        TreeNode* search(TreeNode* x, int val)
        {
            
            if (x==NULL || x->val==val)
                return x;

            if (val < x->val)
                return search(x->left, val);
            else
                return search(x->right, val);     
        
        }

        void power(TreeNode* root1, TreeNode* root2, int target)
        {
            if(root1 != NULL)
            {
            
                if(search(root2,target - (root1->val))!=NULL)
                {
                    flag = true;
                }
                else
                {
                    power(root1->left,root2,target);
                    power(root1->right,root2,target);
                }
            }
        }

    public:

        bool twoSumBSTs(TreeNode* root1, TreeNode* root2, int target) 
        {
            // TreeNode* x;
            power(root1,root2,target);
            return flag;

        }
};

int main ()
{
    Solution A;
    
    return 0;
}